package com.yhao.simpledemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author : yhao
 * @Date : 2022/5/31 - 11:49
 * @Desc : TODO
 */
@RestController
public class TestController {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    @GetMapping("/specialTypeList")
    public List<Map<String, Object>> specialTypeList() {
        // 一会测试一下 数据请求是不是好用
        String sql = "select * from special_type";
        List<Map<String, Object>> map = jdbcTemplate.queryForList(sql);
        return map;
    }

    public static List<String> getUrls(String str) {
        Pattern pattern = Pattern.compile("(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
        Matcher matcher = pattern.matcher(str);
        List<String> urlArr = new ArrayList<>();
        while (matcher.find()) {
            urlArr.add(matcher.group());
        }
        return urlArr;
    }

    public static void main(String[] args) {
        String dd = "slkdfsdf'http://www.baidu.com'sdfhskdfh'3453http://www.suhu.com'sdfasdfasd";
        List<String> urls = getUrls(dd);
        for (String url : urls) {
            System.out.println("url====>>" + url);
        }
    }
}
